package game.driver;

import java.awt.Color;
import game.model.Card;
import game.player.Player;

public class GameLogic {

	private boolean lastCardWild = false;
	private Color wildColor;
	
	/**
	 * 
	 * @param Card, the card which was played
	 * @param Card, the top card of the discard deck
	 */
	public boolean playableCard(Card played, Card top) {
		if ((played.getColor()).equals(Color.BLACK)) {
			lastCardWild = true;
			return true;
		}
		else if (lastCardWild) {
			if(played.getColor().equals(wildColor)) {
				lastCardWild = false;
				return true;
			}
			else {
				return false;
			}
		}
		else if ((played.getColor()).equals(top.getColor())) {
			lastCardWild = false;
			return true;
		}
		else if (played.getValue() == top.getValue()) {
			lastCardWild = false;
			return true;
		}
		else 
			return false;
	}
	
	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 0-9, else false.
	 */
	public boolean isNumberCard(Card c) {
		if(c.getValue() >= 0 && c.getValue() <= 9  && !(c.getColor().equals(Color.BLACK))) 
			return true;
		return false;
	}

	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 10 (reverse), else false.
	 */
	public boolean isReverse(Card c) {
		if(c.getValue() == 10 && !(c.getColor().equals(Color.BLACK))) 
			return true;	
		return false;
	}

	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 11 (skip), else false.
	 */
	public boolean isSkip(Card c) {
		if(c.getValue() == 11 && !(c.getColor().equals(Color.BLACK))) 
			return true;	
		return false;	
	}

	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 12 (draw two), else false.
	 */
	public boolean isDrawTwo(Card c) {
		if(c.getValue() == 12 && !(c.getColor().equals(Color.BLACK))) 
			return true;	
		return false;
	}
	
	
	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 0 & color.Black (Wild), else false.
	 */
	public boolean isWild(Card c) {
		if(c.getValue() == 0 && c.getColor().equals(Color.BLACK)) 
			return true;
		return false;
	}
	
	/**
	 * 
	 * @param Card, played
	 * @return Boolean, true if card is valued 1 & color.Black (Wild), else false.
	 */
	public boolean isWildDrawFour(Card c) {
		if(c.getValue() == 1 && c.getColor().equals(Color.BLACK)) 
			return true;
		return false;
	}
	
	/**
	 * 
	 * @param Player
	 * @return Boolean, true if a player has zero cars (won), else false.
	 */
	public boolean hasPlayerWon(Player p) {
		if(p.hasNumCards() == 0)
			return true;
		return false;
	}
	
	public void setWildColor(Color c) {
		wildColor = c;
	}

}
